package org.duang.push;

import java.util.concurrent.ConcurrentHashMap;

import org.duang.kit.ToolsKit;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.Channel;

public class WebSocket extends WebSocketConnection {

	private static WebSocket socket = null;
	
	public static final ConcurrentHashMap<String, Channel> CHANNEL_MAP = new ConcurrentHashMap<String, Channel>();
	public WebSocket() {
		socketConn = new WebSocketConnection();
	}

	public static WebSocket getInstance() {
		if (null == socket) {
			socket = new WebSocket();
		}
		return socket;
	}
	
	public ServerBootstrap getServerBootstrap() {
		return bootstrap;
	}
	
	public WebSockerChannelHandler getWebSockerChannelHandler() {
		try {
			return (WebSockerChannelHandler)getServerBootstrap().getPipelineFactory().getPipeline().get("handler");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public void close() {
		if(ToolsKit.isNotEmpty(bootstrap)){
			// 关闭资源，线程池等  
			bootstrap.releaseExternalResources(); 
//			bootstrap.shutdown();
		}
	}
	
}
